# -*- coding: UTF-8 -*-

import codecs
import os


class ExplanatoryDictionary():
    def __init__(self):

        self.dictionary = {}
        dict_path = os.path.join(os.path.dirname(__file__),
                                 '..', 'data', 'dict.dct')
        with codecs.open(dict_path, encoding='utf-8', mode='r') as f:
            all_dict = f.read()
            last = 0
            ans = 0
            while True:
                pos = last + 1
                while all_dict[pos] != u'$':
                    pos += 1
                    if pos >= len(all_dict) - 10:
                        break

                if pos >= len(all_dict) - 10:
                    break
                pos2 = last + 1
                while all_dict[pos2] != u'^':
                    pos2 += 1
                    if pos2 >= len(all_dict) - 10:
                        break

                if pos2 >= len(all_dict) - 10:
                    break

                ans += 1
                while all_dict[pos2 - 1].isdigit():
                    pos2 -= 1
                self.dictionary[all_dict[last:pos2]] = all_dict[pos2 + 1:pos]
                last = pos + 1
